package com.mmall.concurrency.example.atomic;

import java.util.concurrent.atomic.AtomicReference;

import com.mmall.concurrency.annoations.ThreadSafe;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@ThreadSafe
public class AtomicExample4 {
	/**
	 * AtomicReference 的compareAndSet(arg1,arg2) 
	 * 方法若arg1为期望的值则把arg2赋值给变量
	 */
	private static AtomicReference<Integer> count = new AtomicReference<>(0);
	public static void main(String args[]) {
		count.compareAndSet(0, 2);
		count.compareAndSet(0, 1); //不执行
		count.compareAndSet(1, 3); //不执行
		count.compareAndSet(2, 4);
		count.compareAndSet(3, 5);
		log.info("count:"+count.get());
	}
}
